package com.example.page;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

public class InternalPage extends AnyPage{

    @FindBy(css = "div[class = \"center\"]>nav>ul")
    public WebElement userPanel;

    @FindBy(xpath = "//nav/ul/li[1]/a")
    public WebElement menuHomeLink;

    @FindBy(xpath = "//nav/ul/li[2]/a")
    public WebElement menuMyProfileLink;

    @FindBy(xpath = "//nav/ul/li[3]/a")
    public WebElement menuUserManagementLink;

    @FindBy(xpath = "//nav/ul/li[4]/a")
    public WebElement menuLogoutLink;

    public AdminPage gotoUserManagement() {
        menuUserManagementLink.click();
        return MyPageFactory.getPage(driverFirefox, AdminPage.class);
    }
    public LoginPage logOut() {
        menuLogoutLink.click();
        wait_().until(alertIsPresent()).accept();
        return MyPageFactory.getPage(driverFirefox, LoginPage.class);
    }

     public FilmsPage returnHomePage() {
        menuHomeLink.click();
        return MyPageFactory.getPage(driverFirefox, FilmsPage.class);
    }

     public boolean isOnThisPage() {
         return menuLogoutLink.isDisplayed();
     }

    @Override
    void tryToOpen(){
        MyPageFactory.getPage(driverFirefox, LoginPage.class).loginAsValid("admin", "123");
    }

}
